import { Application } from "pinus"
import { Dao } from "./dao"

export default function (app: Application) {
    return new ControlDao(app)
}

export class ControlDao extends Dao{
    public constructor(app: Application) {
        super(app)
    }

    async getRobotConfig() {
        const sql = 'select multiple_range as multipleRange, betting_odds as bettingOdds, robot_number as robotNumber,bet_range as betRange  from cms_robot_setting limit 1'
        return this.select(sql,[])
    }

    async getGameConfig() {
        const sql = 'select bet_min as minBet, bet_max as maxBet, settlement_min as minMultiple, settlement_max as maxMultiple from cms_game_setting limit 1'
        return this.select(sql,[])
    }

    async getControlConfig() {
        const sql = 'select id, reserve, progress, rebate  from cms_game_control limit 1'
        return this.select(sql,[])
    }

    async saveProgress(progress: number, id: number) {
        const sql = 'update cms_game_control set progress = ? where id = ?'
        const args = [progress, id]
        return this.select(sql,args)
    }

    async getGameControlSetting() {
        const sql = 'select game_status as gameStatus, game_max as gameMaxMultiple from cms_game_control_setting limit 1'
        return this.select(sql,[])
    }
}
